package com.ityuxin.web;

import com.ityuxin.common.PageResult;
import com.ityuxin.common.QueryPageBean;
import com.ityuxin.common.Result;
import com.ityuxin.domain.Orders;
import com.ityuxin.service.ServiceOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: yyh
 * @Description:
 * @Date:Create：in 2021/4/3 16:09
 * @Modified By：
 */
@RestController
@RequestMapping("/order")
public class ServiceOrderController {

     @Autowired
    private ServiceOrder serviceOrder;


    /**
     * @Author:
     * @Description:查询全部
     * @Date: 12:27 2021/4/3
     * @param: model
     * @return: java.lang.String
     * @Version: 1.0
     */
    @RequestMapping("/findAll")
    public Result findAll(@RequestBody QueryPageBean queryPageBean){
        System.out.println("findAll方法执行了...");
        try {
            PageResult pageResult = serviceOrder.findPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize(), queryPageBean.getQueryString());
            return new Result(true, "查询用户", pageResult);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(true, "查询用户失败");
    }


    /**
     * @Author:
     * @Description:根据id删除
     * @Date: 12:28 2021/4/3
     * @param: id
     * @return: java.lang.String
     * @Version: 1.0
     */
    @RequestMapping("/deleteById")
    public Result deleteById(Integer id){
        try {
            serviceOrder.deleteById(id);
            return new Result(true, "订单删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, "订单删除失败");
        }
    }


    /**
     * @Author:
     * @Description:添加
     * @Date: 12:28 2021/4/3
     * @param: accountService
     * @return: java.lang.String
     * @Version: 1.0
     */
    @RequestMapping("/addserviceitem")
    public  Result  addserviceitem(@RequestBody Orders order){
        try {
            serviceOrder.addserviceitem(order);
            return new Result(true, "订单添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "订单添加删除");
        }

    }


    /**
     * 修改账户
     * @param
     * @return
     */
    @PostMapping("/updateAccount")
    public Result updateserviceitem(@RequestBody Orders order){
        try {
            serviceOrder.updateserviceitem(order);
            return new Result(true, "订单修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, "订单修改失败");
        }
    }


    /**
     * 根据id查询账户信息
     *
     * @param id
     * @return
     */
    @RequestMapping("/findById")
    public Result findById(Integer id) {
        // 根据id查询数据信息
        Orders order = null;
        try {
            order = serviceOrder.findById(id);
            return new Result(true, "查询用户", order);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(false, "查询用户失败");
    }


}
